import { uIsFindColors, uFindColorsClick } from '../utils'
import { menu } from './index'

export default class extends menu {
  constructor({ cFriendsCall, cMenu }) {
    super(cMenu)
    this.cFriendsCall = cFriendsCall
    this.isHome = false
  }

  init(isHome) {
    console.show()
    isHome ? this.isHome = isHome : this.isHome = false
    const { next } = this.cFriendsCall

    if (this.isHome) {
      this.onlyFriendClick()
    } else {
      this.menuEntry()
      this.friend()
    }

    console.hide()
    sleep(1000)
    this.friendListClick()
    this.visitOnlyClick()

    sleep(5000);

    for (let i = 0; i < 10; i++) {
      click(next.x, next.y);
      sleep(5000);

      if (uIsFindColors([this.cFriendsCall.end], 0)) break;
    }
    log('好友寻访完成！');
    return;
  }

  // * 主页 -- 点击好友
  onlyFriendClick() {
    const { home } = this.cFriendsCall

    sleep(500)
    click(home.x, home.y)
  }

  // * 点击好友列表
  friendListClick() {
    const { point, relative } = this.cFriendsCall.list

    uFindColorsClick([point, relative], 0)
  }

  // * 点击访问
  visitOnlyClick() {
    const { point } = this.cFriendsCall.visit

    sleep(5000)
    click(point.x, point.y)
  }
}
